package com.honglu.backend.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.honglu.backend.bo.UUserBo;
import com.honglu.backend.common.shiroToken.TokenManager;
import com.honglu.backend.dao.BannerServiceDao;
import com.honglu.backend.entity.Banner;
import com.honglu.backend.service.BannerService;
import com.honglu.backend.utils.DateUtils;
import com.honglu.utils.UUIDUtils;

@Service
public class BannerServiceImpl implements BannerService {

	@Autowired
	private BannerServiceDao  bannerServiceDao;

	@Override
	public List<Banner> getAll(Banner banner) {
		// TODO Auto-generated method stub
		banner.setCurrentTime(DateUtils.getDate(new Date()));
		return bannerServiceDao.getAll(banner);
	}

	@Override
	public Banner selectByPrimaryKey(String bannerId) {
		// TODO Auto-generated method stub
		return bannerServiceDao.selectByPrimaryKey(bannerId);
	}

	@Override
	public boolean deleteByPrimaryKey(String bannerId) {
		// TODO Auto-generated method stub
		return bannerServiceDao.deleteByPrimaryKey(bannerId);
	}

	@Override
	public int insert(Banner banner) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	@Transactional
	public boolean insertSelective(Banner banner) {
		banner.setBannerId(UUIDUtils.getUUID());
		banner.setAppKey("速贷");
		banner.setState(1);
		banner.setModifyTime(DateUtils.getDate(new Date()));
		banner.setCreateTime(DateUtils.getDate(new Date()));
		UUserBo user = TokenManager.getUser();
		if (user != null) {
			banner.setCreateMan(user.getUserName());
		} else {
			banner.setCreateMan("");
		}
		
		if (user != null) {
			banner.setModifyMan(user.getUserName());
		} else {
			banner.setModifyMan("");
		}
		return bannerServiceDao.insertSelective(banner);
	}

	@Override
	public boolean updateByPrimaryKeySelective(Banner banner) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public int updateByPrimaryKey(Banner banner) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int listAllCount(Banner banner) {
		// TODO Auto-generated method stub
		 banner.setCurrentTime(DateUtils.getDate(new Date()));
		return bannerServiceDao.listAllCount(banner);
	}
	 
	public List<Banner> findBanner(String date) {
		return bannerServiceDao.findBanner(date);
	}
}
